<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 方法一
        /*
            function getSum() {
                let sum = 0;
                for (let i = 0; i < arguments.length; i++) {
                    sum += arguments[i];
                }
                console.log(sum);
            }
            getSum(1, 23, 3, 4, 3, 2);
            */

        // 方法二
        /*
        function getSum(...arr) {
            let sum = 0;
            for (let i = 0; i < arguments.length; i++) {
                sum += arguments[i];
            }
            console.log(sum);
        }
        getSum(1, 23, 3, 4, 3, 2);
        */


        // 展开运算符
        /*
        const a = [123, 4, 5, 2, 5, 5, 3, 3]
        console.log(...a);
        console.log([...a]);
        */

        //箭头函数
        /*
        const fn = () => {
            console.log('Hello,World');
        }
        fn()
        */

        // 数组解构
        /*
        const pc = ['海尔', '联想', '小米', '方正'];
        const [hr, lx, xm, fz] = ['海尔', '联想', '小米', '方正'];
        console.log(hr, lx, xm, fz);
        */

        // 对象解构
        /*
        const pig = {
            name: '佩奇',
            age: 6
        }
        const { name: uname, age } = pig;
        console.log(uname, age);

        const goods = [{
            goodsName: '小米',
            price: 1999
        }]

        const [{ goodsName, price }] = goods
        console.log(goodsName, price);
        */

        //    forEach遍历
        const arr = ['dani', 'peri', 'hudi'];
        arr.forEach((element, index) => {
            console.log(element, index);
        });

        const arr1 = ['peri', 'dani', 'hudi'];
        arr1.forEach(function (element, index) {
            console.log(element, index);
        });
    </script>
</body>

</html>